{extend name="layout"/}
{block name="css"}
<style>
    .linkcolumn{display:none}
</style>
{/block}
{block name="content"}
{empty name="modelList"}
<div class="alert alert-warning">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <i class="fa fa-warning"></i> 请先在'模型管理'中添加栏目内容模型
</div>
{/empty}
{empty name="template_list"}
<div class="alert alert-warning">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <i class="fa fa-warning"></i> 请先在application\home\view\defaults\column\index\目录下添加栏目模板
</div>
{/empty}
{empty name="template_content"}
<div class="alert alert-warning">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <i class="fa fa-warning"></i> 请先在application\home\view\defaults\column\content\目录下添加内容模板
</div>
{/empty}

<form method="post" action="">
    <div class="panel">
        <div class="panel-heading">
              <div class="panel-title">批量添加栏目</div>
            </div>
        <div class="panel-body">
            <fieldset class="form-group">
                <label>所属栏目</label>
                <select id="path" name="path" class="form-control  select2-hidden-accessible" style="width: 50%" data-allow-clear="true" tabindex="-1" aria-hidden="true">
                    <option></option>
                    <option value="0," selected>顶级栏目</option>
                    {volist name="columns" id="vo" }
                    <option value="{$vo.path}{$vo.id},">{:str_repeat('┝┈┈', $vo['deep']-1)}{$vo.title}</option>
                    {/volist}
                </select>
            </fieldset>
            <fieldset class="form-group">
                <label style="clear:both; display: block">栏目类型*</label>
                <label class="custom-control custom-radio radio-inline">
                    <input type="radio" name="type" class="custom-control-input" value="2" checked="">
                    <span class="custom-control-indicator"></span>
                    列表
                </label>
                <label class="custom-control custom-radio radio-inline">
                    <input type="radio" name="type" class="custom-control-input" value="1" >
                    <span class="custom-control-indicator"></span>
                    频道
                </label>
                <label class="custom-control custom-radio radio-inline">
                    <input type="radio" name="type" class="custom-control-input" value="3">
                    <span class="custom-control-indicator"></span>
                    链接
                </label>
                <small class="text-muted" style="clear:both; display: block"></small>
            </fieldset>
            <fieldset class="form-group listApagecolumn">
                <label>栏目名称和标识</label>
                <textarea class="form-control" rows="4" name="modelinfo" placeholder="名称|标识
名称|标识
名称|标识
....."></textarea>
            </fieldset>
            <fieldset class="form-group linkcolumn">
                <label>栏目名称和地址</label>
                <textarea class="form-control" rows="4" name="linkinfo" placeholder="名称|标识|地址
名称|标识|地址
名称|标识|地址
....."></textarea>
            </fieldset>
            <fieldset class="form-group listcolumn">
                <label>内容模型*</label>
                <select id="model_id" name="model_id" class="form-control  select2-hidden-accessible" style="width: 100%" data-allow-clear="true" tabindex="-1" aria-hidden="true">
                    <option></option>
                    {volist name="modelList" id="vo"}
                    <option value="{$key}">{$vo}</option>
                    {/volist}
                </select>
                <small class="text-muted">选择列表栏目使用模型</small>
            </fieldset>
            <fieldset class="form-group listApagecolumn">
                <label>栏目模板*</label>
                <select id="template_list" name="template_list" class="form-control  select2-hidden-accessible" style="width: 100%" data-allow-clear="true" tabindex="-1" aria-hidden="true">
                    <option></option>
                    {volist name="template_list" id="vo"}
                    <option value="{$key}"  data-mid="{$vo.mid}">{$vo.name} {$vo.title}</option>
                    {/volist}
                </select>
            </fieldset>
            <fieldset class="form-group listcolumn">
                <label>内容模板*</label>
                <select id="template_content" name="template_content" class="form-control  select2-hidden-accessible" style="width: 100%" data-allow-clear="true" tabindex="-1" aria-hidden="true">
                    <option></option>
                    {volist name="template_content" id="vo"}
                    <option value="{$key}" data-mid="{$vo.mid}">{$vo.name} {$vo.title}</option>
                    {/volist}
                </select>
            </fieldset>
            <fieldset class="form-group listApagecolumn">
                <label>拓展模型</label>
                <select id="ext_model_id" name="ext_model_id" class="form-control  select2-hidden-accessible" style="width: 100%" data-allow-clear="true" tabindex="-1" aria-hidden="true">
                    <option></option>
                    {volist name="modelList" id="vo"}
                    <option value="{$key}">{$vo}</option>
                    {/volist}
                </select>
                <small class="text-muted"></small>
            </fieldset>
            <fieldset class="form-group listcolumn">
                <label>列表翻页行数*</label>
                <input type="number" class="form-control" name="list_row" placeholder="只能是正整数" value="10">
            </fieldset>
            <div class="row listcolumn">
                <fieldset class="form-group col-sm-6">
                    <label>列表排序</label>
                    <select class="form-control" name="listorder" id="listorder">
                        <option value="orders">排序值</option>
                        <option value="id">ID编号</option>
                        <option value="create_time">创建时间</option>
                        <option value="update_time">更新时间</option>
                        <option value="hits">点击量</option>
                        <option value="rand">随机</option>
                    </select>
                </fieldset>
                <fieldset class="form-group col-sm-6">
                    <label> &nbsp;</label>
                    <select class="form-control" name="listorderway" id="listorderway">
                        <option value="asc" selected>从小到大</option>
                        <option value="desc">从大到小</option>
                    </select>
                </fieldset>
            </div>
            <fieldset class="form-group listcolumn">
                <label  style="clear:both; display: block">列表筛选字段条件</label>
                <div id="listcondition">
                    <small> 无</small>
                </div>
            </fieldset>
            <fieldset class="form-group">
                <label>排序</label>
                <input type="number" class="form-control" name="orders" placeholder="只能是正整数" value="100">
            </fieldset>
            <fieldset class="form-group">
                <label>状态</label>
                <label for="switcher-primary" class="switcher switcher-primary">
                    <input type="checkbox" name="status" value="1" id="switcher-primary" checked="">
                    <div class="switcher-indicator">
                        <div class="switcher-yes">启用</div>
                        <div class="switcher-no">禁用</div>
                    </div>
                    &nbsp;
                </label>
            </fieldset>
            <div class="panel-footer text-right">
                <input type="submit" class="btn btn-primary" value="批量添加栏目">
            </div>
        </div>
    </div>

</form>
{/block}

{block name="javascript"}
<script>
    function setFieldOption(typeid) {
        if (1 == typeid) {
                $('.listcolumn').hide();
                $('.linkcolumn').hide();
                $('.listApagecolumn').show();
                $('#modeTab').show();
            }
            //列表
            if (2 == typeid) {
                $('.linkcolumn').hide();
                $('.listApagecolumn').show();
                $('.listcolumn').show();
                $('#modeTab').show();
            }
            //链接
            if (3 == typeid) {
                $('.listApagecolumn').hide();
                $('.listcolumn').hide();
                $('.linkcolumn').show();
                $('#modeTab').hide();
            }
    }
    $(function () {
        setFieldOption($('input:radio[name="type"]:checked').val());
        //排序选择
        $('#listorder').change(function () {
            if ('rand' == $(this).val()) {
                $('#listorderway').prop('disabled', true);
            } else {
                $('#listorderway').prop('disabled', false);
            }
        });
        var template_list = $('#template_list').select2({
            placeholder: '选择列表模板'
        });
        var template_content = $('#template_content').select2({
            placeholder: '选择内容模板'
        });
        var model_id = $('#model_id').select2({
            placeholder: '选择内容模型'
        }).on("select2:select", function (e) {
            var mid = $(this).val();
            $.get("{:url('getoptionfield')}", {mid: mid},
                    function (data) {
                        if ('' != data) {
                            var checkString = '';
                            var jdata = jQuery.parseJSON(data);
                            for (var vo in jdata) {
                                checkString += '<label class="custom-control custom-checkbox checkbox-inline"><input type="checkbox" name="urls[]" class="custom-control-input" value="' + vo + '" ><span class="custom-control-indicator"></span>' + vo + '(' + jdata[vo] + ')</label>';
                            }
                            $('#listcondition').html(checkString);
                        } else {
                            $('#listcondition').html('无');
                        }
                    },
                    "json"
                    );
            $("#template_list,#template_content").find("option").prop("selected", false);
            $("#template_list").find("option[data-mid=" + mid + "]").eq(0).prop("selected", true);
            $("#template_content").find("option[data-mid=" + mid + "]").eq(0).prop("selected", true);
            template_list.change();
            template_content.change();
        });
        
        $('input:radio[name="type"]').change(function () {
            setFieldOption($(this).val());
        });
        $('#path').select2({
            placeholder: '选择栏目'
        });
        $('#ext_model_id').select2({
            placeholder: '选择栏目拓展模型'
        });
    });
</script>
{/block}